#!/usr/bin/pythonBasics
# -*- coding: UTF-8 -*-

#Author:super

import mysql.connector

try:
	mydb = mysql.connector.connect(
		host = 'localhost',
		port = 3309,
		user = 'root',
		password = 'root',
		database = 'runoob_db'
	)
	#开启事务机制
	mydb.start_transaction()
	mycursor = mydb.cursor()
	mycursor.execute('INSERT INTO sites(NAME,url) VALUES(%s,%s)',('tom','http://www.taobao.com'))
	if mycursor.rowcount>0:
		print('新增成功')
	mydb.commit()
except Exception as e:
	mydb.rollback()
	print(e)
	if 'mydb' in dir():
		mydb.close()
finally:
	if 'mydb' in dir():
		mydb.close()